home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC_Samples / chkbook / chkbkedt.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  4.3 KB  |  156 lines

  1. // CCheckBookEdit.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1999 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. // The class CCheckBookEdit is the application specific implementation
  14. // for CEdit.  When CCheckBookView is in Book View, this edit window is
  15. // displayed.
  16.  
  17. #include "stdafx.h"
  18. #include "chkbook.h"
  19. #include "ChkbkEdt.h"
  20. #include "chkbkvw.h"
  21.  
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CCheckBookEdit
  30.  
  31. CCheckBookEdit::CCheckBookEdit()
  32. {
  33. }
  34.  
  35. CCheckBookEdit::~CCheckBookEdit()
  36. {
  37. }
  38.  
  39.  
  40. BEGIN_MESSAGE_MAP(CCheckBookEdit, CEdit)
  41.     //{{AFX_MSG_MAP(CCheckBookEdit)
  42.     ON_CONTROL_REFLECT(EN_SETFOCUS, OnSetfocus)
  43.     ON_WM_LBUTTONDOWN()
  44.     ON_WM_MOUSEMOVE()
  45.     ON_WM_LBUTTONUP()
  46.     ON_CONTROL_REFLECT(EN_KILLFOCUS, OnKillfocus)
  47.     //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49.  
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CCheckBookEdit message handlers
  52.  
  53. void CCheckBookEdit::OnSetfocus() 
  54. {
  55.     static bSetTabStops = FALSE;
  56.  
  57.     if(!bSetTabStops)
  58.     {
  59.         int nTabStops[] = {30, 60, 200};
  60.         SetTabStops(sizeof(nTabStops)/sizeof(int), nTabStops);
  61.         bSetTabStops = TRUE;
  62.     }
  63.  
  64.     // Get a pointer to the owner document
  65.     m_pDoc = (CCheckBookDoc*)
  66.         ((CFrameWnd*)AfxGetMainWnd())->GetActiveDocument();
  67.  
  68.     CString strCents, strCheckNo, strPayTo, strDate, strMemo;
  69.     CCheckRecord* pRec;
  70.     int y = 0;
  71.  
  72.     CPaintDC dc(this); // device context for painting
  73.     
  74.     // Get the checkbook information
  75.     CCheckBook* chkBk;
  76.     chkBk = m_pDoc->GetCheckBook();
  77.  
  78.     // Column headers will go at the top of the window
  79.     CString strEditContents;
  80.     strEditContents.LoadString(IDS_EDITCONTENTS);
  81.  
  82.     // Add the each check's information into the edit string
  83.     for (UINT nCheck = FIRST_CHECK_NO; 
  84.         nCheck < m_pDoc->m_nNewCheckNo; nCheck++)
  85.     {
  86.         pRec = chkBk->GetCheck(nCheck);
  87.         strCheckNo.Format(_T("%d"), nCheck);
  88.         strCents.Format(_T("%9lu.%02u"), pRec->GetCents() / 100, // Dollars
  89.             pRec->GetCents() % 100); // Cents
  90.  
  91.         pRec->GetPayTo(strPayTo);
  92.         pRec->GetMemo(strMemo);
  93.         // Only print out 20 chars of the Pay To & Memo - not enough space
  94.         // Add "..." if the string is shortened, so the user realizes
  95.         if (strPayTo.GetLength() > 20)
  96.         {
  97.             strPayTo = strPayTo.Left(20);
  98.             strPayTo += _T("...");
  99.         }
  100.         if (strMemo.GetLength() > 20)
  101.         {
  102.             strMemo = strMemo.Left(20);
  103.             strMemo += _T("...");
  104.         }
  105.  
  106.         pRec->GetDate(strDate);
  107.  
  108.         strEditContents += strCheckNo + _T("\t") + strDate + _T("\t") + strPayTo + _T("\t$") + strCents + _T("\r\n\t\t") +  strMemo + _T("\t\t\t\r\n");
  109.     }
  110.  
  111.     // Now we have the edit box's contents, write it to the window
  112.     SetWindowText(strEditContents);
  113.  
  114.     // Highlight the current check
  115.     int startPos = (m_pDoc->m_nCurrentCheckNo - FIRST_CHECK_NO) * 2 + 2;
  116.     SetSel(LineIndex(startPos), LineIndex(startPos + 2));
  117.     InvalidateRect(NULL,FALSE);
  118. }
  119.  
  120. void CCheckBookEdit::OnLButtonDown(UINT nFlags, CPoint point) 
  121. {
  122.     int pos = HIWORD(CharFromPos(point)) - (HIWORD(CharFromPos(point)) % 2);
  123.     if ((pos == 0) || (LineLength(LineIndex(pos)) == 0))
  124.         pos = 2;
  125.     SetSel(LineIndex(pos), LineIndex(pos + 2));
  126.     m_pDoc->m_nCurrentCheckNo = ((pos - 2) / 2) + FIRST_CHECK_NO;
  127. }
  128.  
  129. void CCheckBookEdit::OnMouseMove(UINT nFlags, CPoint point) 
  130. {
  131.     if (nFlags & MK_LBUTTON)
  132.     {
  133.         int pos = HIWORD(CharFromPos(point)) - (HIWORD(CharFromPos(point)) % 2);
  134.         if ((pos == 0) || (LineLength(LineIndex(pos)) == 0))
  135.             pos = 2;
  136.         SetSel(LineIndex(pos), LineIndex(pos + 2));
  137.         m_pDoc->m_nCurrentCheckNo = ((pos - 2) / 2) + FIRST_CHECK_NO;
  138.     }
  139. }
  140.  
  141. void CCheckBookEdit::OnLButtonUp(UINT nFlags, CPoint point) 
  142. {
  143.     int pos = HIWORD(CharFromPos(point)) - (HIWORD(CharFromPos(point)) % 2);
  144.     if ((pos == 0) || (LineLength(LineIndex(pos)) == 0))
  145.         pos = 2;
  146.     SetSel(LineIndex(pos), LineIndex(pos + 2));
  147.     m_pDoc->m_nCurrentCheckNo = ((pos - 2) / 2) + FIRST_CHECK_NO;
  148.     Default();
  149. }
  150.  
  151.  
  152. void CCheckBookEdit::OnKillfocus() 
  153. {
  154.     m_pDoc->UpdateRecord();
  155. }
  156.